package com.taptech.doufu.services.personalcenter;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;

import com.taptech.doufu.ui.activity.UserDetailActivity;
import com.taptech.doufu.util.Md5Util;
import com.taptech.doufu.ui.activity.NewOthersPersonalActivity;
import com.taptech.doufu.ui.activity.NovelSectionDetailsActivity;
import com.taptech.doufu.ui.activity.base.DiaobaoBaseActivity;
import com.taptech.doufu.bean.BaseBean;
import com.taptech.doufu.constant.Constant;
import com.taptech.doufu.listener.HttpResponseListener;
import com.taptech.doufu.bean.personalcenter.PersonalCardInfo;
import com.taptech.doufu.bean.personalcenter.UnreadInfoBean;
import com.taptech.doufu.ui.activity.PersonalFansActivity;
import com.taptech.doufu.util.DiaobaoUtil;
import com.taptech.doufu.net.httputils.HttpRequestObject;
import com.taptech.doufu.net.httputils.HttpResponseObject;
import com.taptech.doufu.net.httputils.HttpUtil;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONObject;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.LinkedList;
import java.util.List;

/**
 * <p>
 * Company: DiaoBao
 * </p>
 *
 * @author huangzh
 * @date 2014-3-17
 */
public class PersonalInfoService<T extends BaseBean> implements HttpResponseListener
{

    private static PersonalInfoService instance = new PersonalInfoService();
    public final static int HANDLE_LOAD_PERSON_INFO = 1101;
    public final static int HANDLE_LOAD_COLLECT_INFO = 1102;
    public final static int HANDLE_LOAD_ATTENTION_INFO = 1103;
    public final static int HANDLE_LOAD_FANS_INFO = 1104;
    public final static int HANDLE_LOAD_DYNAMIC_STATES = 1105;
    public final static int HANDLE_GET_INVITE_CODE = 1106;
    public final static int HANDLE_ADD_COLLECT = 1107;
    public final static int HANDLE_DEL_COLLECT = 1108;
    public final static int HANDLE_LOAD_OTHER_DYNAMICS = 1109;
    public final static int HANDLE_LOAD_PERSON_LETTER = 1110;
    public final static int HANDLE_LOAD_PERSON_LETTER_READ = 1111;
    public final static int HANDLE_LOAD_PERSON_SEND_LETTER = 1112;
    public final static int HANDLE_LOAD_NOFITYS = 1113;
    public final static int HANDLE_REFRESH_NOFITYS = 1114;
    public final static int HANDLE_LOAD_PERSON_LETTER_DELECT = 1115;
    public final static int HANDLE_LOAD_PERSON_POINTS = 1116;
    public final static int HANDLE_LOAD_UNREAD_INFO = 1117;
    public final static int HANDLE_VALIDATE_INVITE_CODE = 1118;
    public final static int HANDLE_LOAD_UNREAD_MESSAGE = 1119;

    public final static int HANDLE_ADD_ATTENTION = 1120;
    public final static int HANDLE_CANCEL_ATTENTION = 1121;
    public final static int HANDLE_CLEAR_UNREAD_LETTER = 1122;
    public final static int HANDLE_HOME_GAME_CIRCLE = 1123;
    public final static int HANDLE_LOAD_NOFIFY = 1124;
    public final static int HANDLE_LOAD_LETTER = 1125;

    public final static int HANDLE_LOAD_COLLECT_TOPIC = 1126;
    public final static int HANDLE_LOAD_COLLECT_ALL = 1127;
    public final static int HANDLE_LOAD_COLLECT_NOVEL = 1128;
    public final static int HANDLE_LOAD_COLLECT_SWEEP = 1129;
    public final static int HANDLE_LOAD_COLLECT_NOTE = 1130;
    public static final int HANDLE_LOAD_COLLECT_DRAW = 1143;
    public static final int HANDLE_LOAD_COLLECT_COS = 1144;
    public final static int HANDLE_LOAD_TOPIC_MINE = 1131;
    public final static int HANDLE_LOAD_NOVEL_MINE = 1132;
    public final static int HANDLE_LOAD_SWEEP_MINE = 1133;
    public final static int HANDLE_LOAD_COLLECT_CARTOON = 1145;

    public final static int HANDLE_TYPE_LOAD_PERSONAL_CENTER_CONTENT = 1134;
    public final static int HANDLE_LOAD_DYNAMIC_MINE = 1135;
    public final static int HANDLE_LOAD_USER_INFO = 1136;
    public final static int HANDLE_LOAD_USER_TAGS = 1137;
    public final static int HANDLE_SAVE_USER_TAGS = 1138;
    public final static int HANDLE_DELETE_COMMENT = 1139;
    public final static int HANDLE_GET_SIGNATURED = 1140;
    public final static int HANDLE_TYPE_LOAD_PERSONAL_CENTER_CONTENT_BY_NICKNAME = 1141;
    public final static int HANDLE_LOAD_TAGS_INFO = 1142;
    public final static int HANDLE_HAS_PERMISSIONS = 1143;
    public final static int HANDLE_HAS_WORKS = 1144;
    public static final int HANDLE_TYPE_GET_SPEAKER_INFO = 1148;
    public static final int HANDLE_LOAD_MYSPEAKER_SEND = 1149;
    public static final int HANDLE_TYPE_GET_SPEAKER_WALL_INFO = 1150;
    public static final int HANDLE_TYPE_LOAD_MY_PERSONAL_CENTER_CONTENT = 1151;

    public int fansCount;

    public final static String DEFAUL_URL = "http://" + Constant.HOST_NAME + "/index.php/user/msg_center/";

    public static final String DYNAMIC_BASE_URL = "http://" + Constant.HOST_NAME + "/index.php/user/activity/";

    private List<PersonalCardInfo> fans = new LinkedList<PersonalCardInfo>();
    private List<PersonalCardInfo> attentions = new LinkedList<PersonalCardInfo>();

    private UnreadInfoBean unreadInfo = new UnreadInfoBean();
    /**
     * adsfasd
     */

    private boolean infoChanged, attentionsChanged;
    private String following;

    private PersonalInfoService()
    {

    }

    public static PersonalInfoService getInstance()
    {
        return instance;
    }


    static public void enterOthersPersonalCenter(Context context , String uid){
        if (uid != null ) {
            UserDetailActivity.Companion.startActivity(context,uid);
        }
    }



    public static void sendSpeakerInfo(HttpResponseListener listener, String message, String direct_publish, String bugles_id){
        HttpRequestObject request = new HttpRequestObject();
        List<NameValuePair> list = new LinkedList<NameValuePair>();
        NameValuePair value;
        value = new BasicNameValuePair("message", message);
        list.add(value);
        value = new BasicNameValuePair("direct_publish", direct_publish);
        list.add(value);
        value = new BasicNameValuePair("bugles_id", bugles_id);
        list.add(value);
        request.setHandleType(HANDLE_LOAD_MYSPEAKER_SEND);
        request.setUrl(Constant.HOST_NAME_SECOND + "/index.php/buglesrecords/save_bugles");
        request.setListener(listener);
        request.setData(list);
        HttpUtil.sendPostRequest(request);
    }



    public void addCollectes(String articleId, HttpResponseListener listener)
    {
        HttpRequestObject request = new HttpRequestObject();
        request.setHandleType(HANDLE_ADD_COLLECT);
        String url = Constant.HOST_NAME_SECOND + "/index.php/post/add_fav?uid=" + AccountService.getInstance().getUserUid() + "&article_id=" + articleId;
        if(listener instanceof NovelSectionDetailsActivity){
//            url = url + "&object_type=1";// 详情 1
            url = url + "&object_type=5";// 详情 1
        } else
        {
            url = url + "&object_type=5";// 整个 5
        }
        request.setUrl(url);

        request.setListener(listener);
        HttpUtil.sendGetRequest(request);
    }

    public void delSweep(String review_id, HttpResponseListener listener)
    {
        HttpRequestObject request = new HttpRequestObject();
        request.setHandleType(HANDLE_DEL_COLLECT);
        String url = Constant.HOST_NAME_SECOND + "/index.php/novel_review/remove";
        List<NameValuePair> lsit = new LinkedList<NameValuePair>();
        NameValuePair value;
        value = new BasicNameValuePair("review_id", review_id);
        lsit.add(value);
        request.setUrl(url);
        request.setData(lsit);
        request.setListener(listener);
        HttpUtil.sendPostRequest(request);
    }

    public void delCollectes(String articleId, HttpResponseListener listener)
    {
        HttpRequestObject request = new HttpRequestObject();
        request.setHandleType(HANDLE_DEL_COLLECT);
        String url = Constant.HOST_NAME_SECOND + "/index.php/post/del_fav?uid=" + AccountService.getInstance().getUserUid() + "&article_id=" + articleId;
        if (listener instanceof NovelSectionDetailsActivity)
        {
//            url = url + "&object_type=1";// 单篇小说1
            url = url + "&object_type=5";// 单篇小说1
        } else
        {
            url = url + "&object_type=5";// 整本5
        }
        request.setUrl(url);
        request.setListener(listener);
        HttpUtil.sendGetRequest(request);
    }

    public void delTopic(String topicId, HttpResponseListener listener)
    {
        HttpRequestObject request = new HttpRequestObject();
        request.setHandleType(HANDLE_DEL_COLLECT);
        String url = Constant.HOST_NAME_SECOND + "/index.php/post/removeTopicReply";
        List<NameValuePair> lsit = new LinkedList<NameValuePair>();
        NameValuePair value;
        value = new BasicNameValuePair("id", topicId);
        lsit.add(value);
        request.setUrl(url);
        request.setData(lsit);
        request.setListener(listener);
        HttpUtil.sendPostRequest(request);
    }

    public void delComment(String topicId, HttpResponseListener listener)
    {
        HttpRequestObject request = new HttpRequestObject();
        request.setHandleType(HANDLE_DEL_COLLECT);
        String url = Constant.HOST_NAME_SECOND + "/index.php/comment/remove";
        List<NameValuePair> lsit = new LinkedList<NameValuePair>();
        NameValuePair value;
        value = new BasicNameValuePair("id", topicId);
        lsit.add(value);
        request.setUrl(url);
        request.setData(lsit);
        request.setListener(listener);
        HttpUtil.sendPostRequest(request);
    }

    public void delReply(String topicId, HttpResponseListener listener)
    {
        HttpRequestObject request = new HttpRequestObject();
        request.setHandleType(HANDLE_DEL_COLLECT);
        String url = Constant.HOST_NAME_SECOND + "/index.php/comment/removeReply";
        List<NameValuePair> lsit = new LinkedList<NameValuePair>();
        NameValuePair value;
        value = new BasicNameValuePair("id", topicId);
        lsit.add(value);
        request.setUrl(url);
        request.setData(lsit);
        request.setListener(listener);
        HttpUtil.sendPostRequest(request);
    }

    public void loadAttentions(String last, HttpResponseListener listener)
    {
        HttpRequestObject request = new HttpRequestObject();
        int size = Constant.PAGE_SIZE_30;
        request.setHandleType(HANDLE_LOAD_ATTENTION_INFO);
        request.setUrl(DEFAUL_URL + "user_attention?&last=" + last + "&size=" + size + "&uid=" + AccountService.getInstance().getUserUid());

        if (listener != null)
        {
            request.setListener(listener);

            HttpUtil.sendGetRequest(request);


        } else
        {
            request.setListener(this);
            HttpUtil.sendGetRequest(request);
        }

    }

    public void loadFans(String last, HttpResponseListener listener)
    {
        HttpRequestObject request = new HttpRequestObject();
        int size = Constant.PAGE_SIZE_30;
        request.setHandleType(HANDLE_LOAD_FANS_INFO);
        request.setUrl(DEFAUL_URL + "user_fans?&last=" + last + "&size=" + size + "&uid=" + AccountService.getInstance().getUserUid());
        if (listener != null)
        {
            request.setListener(listener);
        } else
        {
            request.setListener(this);
        }
        if (listener instanceof PersonalFansActivity)
        {
            HttpUtil.sendLockedGetRequest(request, (DiaobaoBaseActivity) listener);
        } else
        {
            HttpUtil.sendGetRequest(request);
        }

    }

    public void loadNofifys(String last, int update, HttpResponseListener listener)
    {
        HttpRequestObject request = new HttpRequestObject();
        String url = "http://" + Constant.HOST_NAME + "/index.php/notify/index?uid=" + AccountService.getInstance().getUserUid() + "&size=" + Constant.COMMENT_SIZE + "&last=" + last;
        if (last.equals("0"))
        {
            request.setHandleType(HANDLE_REFRESH_NOFITYS);
        } else
        {
            request.setHandleType(HANDLE_LOAD_NOFITYS);
        }

        request.setUrl(url);
        if (listener != null)
        {
            request.setListener(listener);
        } else
        {
            request.setListener(this);
        }

        HttpUtil.sendGetRequest(request);

    }



    // api.doufu.la/index.php/novel_review/user
    public void loadDynamicStates(int last, int type, HttpResponseListener listener)
    {
        HttpRequestObject request = new HttpRequestObject();
        request.setHandleType(HANDLE_LOAD_DYNAMIC_STATES);
        String url = DYNAMIC_BASE_URL + "mine?uid=" + AccountService.getInstance().getUserUid() + "&size=" + Constant.PAGE_SIZE_100 + "&last=" + last;
        if (type == 0)
        {
            url = "http://" + Constant.HOST_NAME + "/index.php/novel_review/user?uid=" + AccountService.getInstance().getUserUid() + "&size=" + Constant.PAGE_SIZE_100 + "&last=" + last;// 文评
        } else if (type == 1)
        {
            url = url + "&op_type[]=6";// 话题
        } else if (type == 2)
        {
            url = url + "&op_type[]=1&op_type[]=13";// 评论
        } else if (type == 3)
        {
            url = url + "&op_type[]=10";// 收藏
        }
        request.setUrl(url);
        request.setRequestData(type);
        request.setListener(listener);
        HttpUtil.sendGetRequest(request);
    }

    public void loadOtherDynamicStates(String userID, int last, HttpResponseListener listener)
    {
        HttpRequestObject request = new HttpRequestObject();
        request.setHandleType(HANDLE_LOAD_OTHER_DYNAMICS);
        request.setUrl(DYNAMIC_BASE_URL + "other?uid=" + userID + "&size=" + Constant.PAGE_SIZE_100 + "&last=" + last);
        request.setListener(listener);

        HttpUtil.sendGetRequest(request);

    }

    public void loadPersonalPoints(HttpResponseListener listener)
    {
        HttpRequestObject request = new HttpRequestObject();
        request.setHandleType(HANDLE_LOAD_PERSON_POINTS);
        request.setUrl("http://" + Constant.HOST_NAME + "/index.php/user/msg_center/get_user_score?uid=" + AccountService.getInstance().getUserUid());
        request.setListener(listener);
        HttpUtil.sendGetRequest(request);
    }

    public void addAttention(String userId, HttpResponseListener listener, Activity activity)
    {
        HttpRequestObject request = new HttpRequestObject();
        request.setHandleType(HANDLE_ADD_ATTENTION);
        request.setUrl(DEFAUL_URL + "user_attracted?attention_user_uid=" + userId + "&user_uid=" + AccountService.getInstance().getUserUid());
        request.setListener(listener);
        HttpUtil.sendLockedGetRequest(request, activity);
    }

    public void cancelAttention(String userId, HttpResponseListener listener, Activity activity)
    {
        HttpRequestObject request = new HttpRequestObject();
        request.setHandleType(HANDLE_CANCEL_ATTENTION);
        request.setUrl(DEFAUL_URL + "cancel_attracted?attention_user_uid=" + userId + "&user_uid=" + AccountService.getInstance().getUserUid());
        request.setListener(listener);
        HttpUtil.sendLockedGetRequest(request, activity);
    }

    public void getInviteCode(int communityId, HttpResponseListener listener, Activity activity)
    {
        String url = DEFAUL_URL + "user_invite?uid=" + AccountService.getInstance().getUserUid();
        if (communityId != 0)
        {
            url = url + "&community_id=" + communityId;
        }
        HttpRequestObject request = new HttpRequestObject();
        request.setHandleType(HANDLE_GET_INVITE_CODE);
        request.setUrl(url);
        request.setListener(listener);
        HttpUtil.sendLockedGetRequest(request, activity);
    }

    public void validateInviteCode(String code, HttpResponseListener listener)
    {
        String url = Constant.BASE_URL + "member/invitation_calibrate?uid=" + AccountService.getInstance().getUserUid() + "&code=" + code + "&device_identity=" + DiaobaoUtil.getIMEI() + "&key=" + Md5Util.getMD5Str(DiaobaoUtil.getIMEI() + Constant.DIAOBAO_KEY);
        HttpRequestObject request = new HttpRequestObject();
        request.setHandleType(HANDLE_VALIDATE_INVITE_CODE);
        request.setUrl(url);
        request.setListener(listener);
        HttpUtil.sendLockedGetRequest(request, (DiaobaoBaseActivity) listener);
    }

    public void loadUnreadInfos(HttpResponseListener listener)
    {
        String url = "http://" + Constant.HOST_NAME + "/index.php/notify/unread_num?uid=" + AccountService.getInstance().getUserUid();
        HttpRequestObject request = new HttpRequestObject();
        request.setHandleType(HANDLE_LOAD_UNREAD_INFO);
        request.setUrl(url);
        if (listener == null)
        {
            request.setListener(this);
        } else
        {
            request.setListener(listener);
        }
        HttpUtil.sendGetRequest(request);
    }



    @SuppressWarnings("unchecked")
    @Override
    public void handleResponse(int handleType, HttpResponseObject response)
    {
        try
        {
            if (response.getStatus() == Constant.STATUS_SUCCESS)
            {
                switch (handleType)
                {
                    case HANDLE_LOAD_ATTENTION_INFO:
                        setAttentions(DiaobaoUtil.jsonArray2BeanList(PersonalCardInfo.class, (JSONArray) response.getData()));
                        break;

                    case HANDLE_LOAD_FANS_INFO:
                        setFans(DiaobaoUtil.jsonArray2BeanList(PersonalCardInfo.class, (JSONArray) response.getData()));
                        break;
                    case HANDLE_LOAD_UNREAD_MESSAGE:
                        unreadInfo.setJson((JSONObject) response.getData());
                        refreshUnreadInfo();
                        break;
                }
            }
        } catch (Exception e)
        {
            e.printStackTrace();
        }
    }


    public boolean delMyAttentions(String uid)
    {
        try
        {
            int index = -1;
            for (PersonalCardInfo person : attentions)
            {
                index++;
                if (person != null && person.getUid() != null && person.getUid().equals(uid))
                {
                    infoChanged = true;
                    break;
                }
            }
            if (index > 0)
                attentions.remove(index);
        } catch (Exception e)
        {
            e.printStackTrace();
        }
        return false;
    }

    public boolean addMyAttentions(PersonalCardInfo userCard)
    {
        infoChanged = true;
        for (PersonalCardInfo user : attentions)
        {
            if (user.getUid().equals(userCard.getUid()))
                return true;
        }
        return attentions.add(userCard);
    }


    public List<PersonalCardInfo> getFans()
    {
        return fans;
    }

    public void setFans(List<PersonalCardInfo> fans)
    {
        this.fans = fans;
        fansCount = fans.size();
        infoChanged = true;
    }

    public List<PersonalCardInfo> getAttentions()
    {
        return attentions;
    }

    public void setAttentions(List<PersonalCardInfo> attentions)
    {
        this.attentions = attentions;
        infoChanged = true;
    }

    public String getInviteMessage(String inviteCode, String groupName)
    {
        String left = "";
        if (groupName != null)
        {
            left = Constant.INVITE_GROUP_LEFT.replace("XXX", groupName);
        } else
        {
            left = Constant.INVITE_LEFT;
        }
        return left + inviteCode + Constant.INVITE_RIGHT;
    }

    public String getWexinInviteMessage(String inviteCode, String groupName)
    {
        String left = "";
        if (groupName != null)
        {
            left = Constant.INVITE_GROUP_LEFT.replace("XXX", groupName);
        } else
        {
            left = Constant.INVITE_LEFT;
        }
        return left + inviteCode + Constant.INVITE_RIGHT_WEIXIN;
    }

    public UnreadInfoBean getUnreadInfo()
    {
        return unreadInfo;
    }

    public void loadOtherAttentions(String uid, String last, HttpResponseListener listener)
    {
        HttpRequestObject request = new HttpRequestObject();
        request.setHandleType(HANDLE_LOAD_ATTENTION_INFO);
        int size = Constant.PAGE_SIZE_30;
        request.setUrl(DEFAUL_URL + "user_attention?&last=" + last + "&size=" + size + "&uid=" + uid);

        request.setListener(listener);
        HttpUtil.sendGetRequest(request);
    }

    public void loadOtherFans(String uid, String last, HttpResponseListener listener)
    {
        HttpRequestObject request = new HttpRequestObject();
        request.setHandleType(HANDLE_LOAD_FANS_INFO);
        int size = Constant.PAGE_SIZE_30;
        request.setUrl(DEFAUL_URL + "user_fans?&last=" + last + "&size=" + size + "&uid=" + uid);
        request.setListener(listener);
        HttpUtil.sendGetRequest(request);
    }

    public void loadUnreadMessages()
    {
        HttpRequestObject request = new HttpRequestObject();
        request.setHandleType(HANDLE_LOAD_UNREAD_MESSAGE);
        request.setUrl(Constant.BASE_URL + "notify/unread_num?&uid=" + AccountService.getInstance().getUserUid());
        request.setListener(this);
        HttpUtil.sendGetRequest(request);
    }

    public void refreshUnreadInfo()
    {
        int count = DiaobaoUtil.String2Int(unreadInfo.getLetter()) + DiaobaoUtil.String2Int(unreadInfo.getNotify());
    }

    public boolean isAttentionsChanged()
    {
        return attentionsChanged;
    }

    public void setAttentionsChanged(boolean attentionsChanged)
    {
        this.attentionsChanged = attentionsChanged;
    }


    public void clearPersonalInfo()
    {
        fans.clear();
        attentions.clear();
        fansCount = 0;
        unreadInfo.setLetter("0");
        unreadInfo.setNotify("0");

    }

    public boolean refreshMyAttentions()
    {
        try
        {
            List<PersonalCardInfo> newAttentions = new LinkedList<PersonalCardInfo>();
            for (PersonalCardInfo person : attentions)
            {

                if (person.getFollowing().equals("0"))
                {
                    infoChanged = true;
                    continue;
                }
                newAttentions.add(person);
            }
            attentions.clear();
            attentions.addAll(newAttentions);
        } catch (Exception e)
        {
            e.printStackTrace();
        }
        return false;
    }

    /**
     * 收藏接口
     *
     * @param listener
     * @param last
     * @param fav_type
     * @param type
     * @param order
     */
    public void loadCollect(HttpResponseListener listener, String last, int fav_type, int type,int order)
    {
        HttpRequestObject request = new HttpRequestObject();
        request.setHandleType(type);
        if (order > 0) {
            request.setUrl(Constant.HOST_NAME_SECOND + "/index.php/favorite?size=20&last=" + last + "&fav_type=" + fav_type+"&order="+order);/*order=1按时间排序*/
        }else{
            request.setUrl(Constant.HOST_NAME_SECOND + "/index.php/favorite?size=20&last=" + last + "&fav_type=" + fav_type);/*order=1按时间排序*/
        }
        request.setListener(listener);
        HttpUtil.sendGetRequest(request);
    }

    /**
     * 发表的话题，小说
     *
     * @param listener
     * @param last
     * @param topic_type
     */
    public void loadPersonalTopicMine(HttpResponseListener listener, String last, int topic_type, int pageIndex, String userId)
    {

        HttpRequestObject request = new HttpRequestObject();
        request.setHandleType(HANDLE_LOAD_TOPIC_MINE);
        request.setUrl(Constant.HOST_NAME_SECOND + "/index.php/topic/mine?size=20&last=" + last + "&topic_type=" + topic_type + "&user_id=" + userId);
        request.setListener(listener);
        HttpUtil.sendGetRequest(request);
    }


    /**
     * 拉取个人中心的发表内容简表数据
     *
     * @param listener
     * @param userId   用MineContentBean保存
     */
    public static void loadPersonalCenterContent(HttpResponseListener listener, String userId)
    {
        HttpRequestObject request = new HttpRequestObject();
        request.setHandleType(HANDLE_TYPE_LOAD_PERSONAL_CENTER_CONTENT);
        request.setUrl(Constant.HOST_NAME_SECOND + "/index.php/member/mine?user_id=" + userId);
        request.setListener(listener);
        HttpUtil.sendGetRequest(request);
    }

    public void getMySpeakerInfo(HttpResponseListener listener){
        HttpRequestObject request = new HttpRequestObject();
        request.setHandleType(HANDLE_TYPE_GET_SPEAKER_INFO);
        request.setUrl(Constant.HOST_NAME_SECOND + "/index.php/buglesrecords/bugles");
        request.setListener(listener);
        HttpUtil.sendGetRequest(request);
    }

    public void getSpeakerWallInfo(HttpResponseListener listener, String record_id){
        HttpRequestObject request = new HttpRequestObject();
        request.setHandleType(HANDLE_TYPE_GET_SPEAKER_WALL_INFO);
        request.setUrl(Constant.HOST_NAME_SECOND + "/index.php/buglesrecords/bugles_list?record_id=" + record_id);
        request.setListener(listener);
        HttpUtil.sendGetRequest(request);
    }





    /**
     * 拉取个人中心的发表内容简表数据
     *
     * @param listener
     * @param user_nickName 用MineContentBean保存
     */
    public static void loadPersonalCenterContent_by_userNickName(HttpResponseListener listener, String user_nickName)
    {
        HttpRequestObject request = new HttpRequestObject();
        request.setHandleType(HANDLE_TYPE_LOAD_PERSONAL_CENTER_CONTENT);
        try
        {
            request.setUrl(Constant.HOST_NAME_SECOND + "/index.php/member/mine?nickname=" + URLEncoder.encode(user_nickName, "utf-8"));
        } catch (UnsupportedEncodingException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        request.setListener(listener);
        HttpUtil.sendGetRequest(request);
    }

    /**
     * 拉取个人的话题列表
     *
     * @param listener
     * @param last
     * @param pageIndex
     * @param userId
     */
    public void loadPersonalCenterTopicList(HttpResponseListener listener, String last, int pageIndex, String userId)
    {
        HttpRequestObject request = new HttpRequestObject();
        request.setHandleType(HANDLE_LOAD_TOPIC_MINE);
        request.setUrl(Constant.HOST_NAME_SECOND + "/index.php/topic/mine?size=20&last=" + last + "&topic_type=" + 16 + "&user_id=" + userId);
        request.setListener(listener);
        request.setPageIndex(pageIndex);
        HttpUtil.sendGetRequest(request);
    }

    /**
     * 拉取个人的文评列表
     *
     * @param listener
     * @param last
     * @param pageIndex
     * @param userId
     */

    public void loadPersonalCenterSweepList(HttpResponseListener listener, String last, int pageIndex, String userId)
    {
        HttpRequestObject request = new HttpRequestObject();
        request.setHandleType(HANDLE_LOAD_SWEEP_MINE);
        request.setUrl(Constant.HOST_NAME_SECOND + "/index.php/novel_review/user?size=20&last=" + last + "&uid=" + userId);
        request.setListener(listener);
        request.setPageIndex(pageIndex);
        HttpUtil.sendGetRequest(request);
    }

    public void loadDynamicMine(HttpResponseListener listener, String last, int pageIndex, String userId)
    {

        HttpRequestObject request = new HttpRequestObject();
        request.setHandleType(HANDLE_LOAD_DYNAMIC_MINE);
        try
        {
            request.setUrl(Constant.HOST_NAME_SECOND + "/index.php/activities/mine?size=20&user_id=" + userId + "&last=" + URLEncoder.encode(last, "utf-8"));
        } catch (UnsupportedEncodingException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        request.setListener(listener);
        request.setPageIndex(pageIndex);
        HttpUtil.sendGetRequest(request);
    }


    /**
     * 获得个人标签信息
     *
     * @param listener
     * @param userId
     */

    public void loadUserTagsInfo(HttpResponseListener listener, String userId)
    {
        HttpRequestObject request = new HttpRequestObject();
        request.setHandleType(HANDLE_LOAD_USER_TAGS);
        request.setUrl(Constant.HOST_NAME_SECOND + "/index.php/member/get_tags?uid=" + userId);
        request.setListener(listener);
        HttpUtil.sendGetRequest(request);
    }

    public void saveUserTagsInfo(HttpResponseListener listener, String[] tags)
    {
        HttpRequestObject request = new HttpRequestObject();
        List<NameValuePair> lsit = new LinkedList<NameValuePair>();
        NameValuePair value;
        for (String tag : tags)
        {
            value = new BasicNameValuePair("tags[]", tag);
            lsit.add(value);
        }
        request.setHandleType(HANDLE_SAVE_USER_TAGS);
        request.setUrl(Constant.HOST_NAME_SECOND + "/index.php/member/save_tags/");
        request.setListener(listener);
        request.setData(lsit);
        HttpUtil.sendPostRequest(request);
    }


    public void hasPermissionsRequest(HttpResponseListener listener, String object_type)
    {
        HttpRequestObject request = new HttpRequestObject();
        request.setHandleType(HANDLE_HAS_PERMISSIONS);
        request.setUrl(Constant.HOST_NAME_SECOND + "/index.php/member/hasPermissions" + "?object_type=" + object_type);
        request.setListener(listener);
        HttpUtil.sendGetRequest(request);
    }

    public void getUserWorksRequest(HttpResponseListener listener, String user_id)
    {
        HttpRequestObject request = new HttpRequestObject();
        request.setHandleType(HANDLE_HAS_WORKS);
        request.setUrl(Constant.HOST_NAME_SECOND + "/index.php/member/statistics" + "?user_id=" + user_id);
        request.setListener(listener);
        HttpUtil.sendGetRequest(request);
    }

    public void getUserWorksRequest(HttpResponseListener listener, String user_id , String nickName)
    {
        HttpRequestObject request = new HttpRequestObject();
        request.setHandleType(HANDLE_HAS_WORKS);
        request.setUrl(Constant.HOST_NAME_SECOND + "/index.php/member/statistics" + "?nickname=" + nickName);
        request.setListener(listener);
        HttpUtil.sendGetRequest(request);
    }

}
